package cn.wd.web.controller;


import cn.wd.domain.LoginLog;
import cn.wd.page.PageResult;
import cn.wd.qo.LoginLogQueryObject;
import cn.wd.service.ILoginLogService;
import cn.wd.vo.JsonResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/loginLog")
public class LoginLogController {

    private final ILoginLogService loginLogService;

    public LoginLogController(ILoginLogService loginLogService) {
        this.loginLogService = loginLogService;
    }

    @RequestMapping("/list")
    public JsonResult<PageResult<LoginLog>> query(LoginLogQueryObject qo) {
        return JsonResult.success(loginLogService.query(qo));
    }

    @RequestMapping("/saveOrUpdate")
    public JsonResult<?> saveOrUpdate(@RequestBody LoginLog loginLog) {
        if (loginLog.getId() != null) {
            loginLogService.updateById(loginLog);
        } else {
            loginLogService.save(loginLog);
        }

        return JsonResult.success();
    }

    @RequestMapping("/delete")
    public JsonResult<?> delete(Long id) {
        if (id == null) {
            return JsonResult.failed("删除的 id 不能为空!");
        }

        loginLogService.deleteById(id);
        return JsonResult.success();
    }

    @RequestMapping("/batchDelete")
    public JsonResult<?> batchDelete(@RequestBody(required=false) Long[] deletedIds) {
        loginLogService.batchDelete(deletedIds);
        return JsonResult.success();
    }
}
